import { IPSControl } from '../ipscontrol';
import { IPSRawItemBase } from '../ipsraw-item-base';
import { IPSRawItemContainer } from '../ipsraw-item-container';
import { IPSDBRawItemPortletPart } from './ipsdbraw-item-portlet-part';
import { PSDBPortletPartImpl } from './psdbportlet-part-impl';
import { IPSSysImage } from '../../res/ipssys-image';

export class PSDBRawItemPortletPartImpl extends PSDBPortletPartImpl implements IPSDBRawItemPortletPart, IPSRawItemContainer {
  protected contentpscontrol: IPSControl | null = null;

  getContentPSControl(): IPSControl | null {
    if (this.contentpscontrol != null) return this.contentpscontrol;
    const value = this.M.getContentPSControl;
    if (value == null) {
      return null;
    }
    this.contentpscontrol = this.findPSControl(value);
    return this.contentpscontrol;
  }

  get contentPSControl(): IPSControl | null {
    return this.getContentPSControl();
  }

  getContentPSControlMust(): IPSControl {
    const value = this.getContentPSControl();
    if (value == null) {
      throw new Error('未指定内容部件');
    }
    return value;
  }

  get contentType(): 'RAW' | 'HTML' | 'IMAGE' | 'MARKDOWN' | 'VIDEO' | 'PLACEHOLDER' | 'DIVIDER' | 'INFO' | 'WARNING' | 'ERROR' | 'USER' | 'USER2' {
    return this.M.contentType;
  }

  get htmlContent(): string {
    return this.M.htmlContent;
  }

  protected psrawitem: IPSRawItemBase | null = null;

  getPSRawItem(): IPSRawItemBase | null {
    if (this.psrawitem != null) return this.psrawitem;
    const value = this.M.getPSRawItem;
    if (value == null) {
      return null;
    }
    this.psrawitem = this.getPSModel4('control.IPSRawItemBase', value, 'getPSRawItem') as IPSRawItemBase;
    return this.psrawitem;
  }

  get psRawItem(): IPSRawItemBase | null {
    return this.getPSRawItem();
  }

  getPSRawItemMust(): IPSRawItemBase {
    const value = this.getPSRawItem();
    if (value == null) {
      throw new Error('未指定直接内容对象');
    }
    return value;
  }

  protected pssysimage: IPSSysImage | null = null;

  getPSSysImage(): IPSSysImage | null {
    if (this.pssysimage != null) return this.pssysimage;
    const value = this.M.getPSSysImage;
    if (value == null) {
      return null;
    }
    this.pssysimage = this.getPSModel4('res.IPSSysImage', value, 'getPSSysImage') as IPSSysImage;
    return this.pssysimage;
  }

  get psSysImage(): IPSSysImage | null {
    return this.getPSSysImage();
  }

  getPSSysImageMust(): IPSSysImage {
    const value = this.getPSSysImage();
    if (value == null) {
      throw new Error('未指定图片内容');
    }
    return value;
  }

  get portletType(): 'LIST' | 'CHART' | 'VIEW' | 'HTML' | 'TOOLBAR' | 'ACTIONBAR' | 'CUSTOM' | 'APPMENU' | 'CONTAINER' | 'RAWITEM' {
    return this.M.portletType;
  }

  get rawContent(): string {
    return this.M.rawContent;
  }

  get rawItemHeight(): number {
    return this.M.rawItemHeight != null ? this.M.rawItemHeight : 0.0;
  }

  get rawItemWidth(): number {
    return this.M.rawItemWidth != null ? this.M.rawItemWidth : 0.0;
  }

  get cls(): string {
    return 'PSDBRawItemPortletPartImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.IPSRawItem' || cls == 'control.IPSRawItemContainer' || cls == 'control.dashboard.IPSDBRawItemPortletPart') return true;
    return super.instanceof(cls);
  }
}
